// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import VueLazyLoad from 'vue-lazyload'
import LyTab from 'ly-tab'
import { Uploader,Tab, Tabs,Loading,Popup,Actionsheet,Collapse, CollapseItem,Icon, Toast} from 'vant';

import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

Vue.use(Tab).use(Tabs).use(Icon).use(Loading).use(Popup).use(LyTab).use(Actionsheet).use(Collapse).use(CollapseItem);
import 'styles/index.scss'
import 'swiper/dist/css/swiper.css';
import 'js/zoom.js'

Vue.config.productionTip = false

Vue.prototype.$axios=axios;
//图片上传
Vue.use(Uploader).use(Tab).use(Tabs).use(VueLazyLoad,{
	loading: require('./assets/image/game_icon.png')
});
//获取token并发送给后台

NProgress.inc(0.5)
NProgress.configure({ easing: 'ease', speed: 200, showSpinner: false })


router.beforeEach((to, from, next) => {
  NProgress.start();
//   if(!navigator.onLine){
//      Toast("网络连接失败，请检查网络设置")
//    }
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
      if (store.state.loginInfo) {  // 通过vuex state获取当前的token是否存在
          next();
      }
      else {
          next({
              path: '/login',
              query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
          })
      }
  }
  else {
      next();
  }
})
router.afterEach(transition => {
    NProgress.done();
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
